//
//  JFBConfirmInStorage.m
//  ios-supplier
//
//  Created by Benlai on 15/8/27.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "JFBConfirmInStorage.h"

@implementation JFBConfirmInStorage

+ (NSURLSessionDataTask *)confirmInStorage:(void (^)(BOOL isSuccess, NSError *error))block orderID:(NSUInteger)order_id storage:(NSArray *)storage
{
    NSError *parseError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject: storage options:NSJSONWritingPrettyPrinted error:&parseError];
    NSString *storageStr = [[NSString alloc] initWithData: jsonData encoding:NSUTF8StringEncoding];
    
    NSDictionary *parameter = @{@"order_id":[NSNumber numberWithInteger: order_id],
                                @"storage": storageStr};
    
    return [[JFBAPIClient sharedClient: true] GET:@"/shop/purchase/so/instorage.json" parameters:parameter success:^(NSURLSessionDataTask * __unused task, id JSON) {
        NSObject * error = [JSON valueForKey:@"error"]
        ;
        if( error == [NSNull null] ) {
            block(true, nil);
        } else {
            block(false, nil);
        }
    } failure:^(NSURLSessionDataTask *__unused task, NSError *error) {
        block(false, error);
    }];
}
@end
